package com.diyizu.youdianda.common;

import lombok.Data;

/**
 * 通用返回结果,封装服务器响应的数据
 * @param <T>
 */
@Data
public class R<T> {
    private Integer errno; //错误编码? 暂时不知道正确返回什么

    private String errmsg; //错误信息

    private T data; //数据

    public static <E> R<E> success(E object) {
        R<E> r = new R<>();
        r.data = object;
        r.errno = 0;
        return r;
    }

    public static <M> R<M> error(String msg) {
        R<M> r = new R<>();
        r.errmsg = msg;
        r.errno = 1;
        return r;
    }

    public static <M> R<M> error(String msg, Integer code){
        R<M> r = new R<>();
        r.errmsg = msg;
        r.errno = code;
        return r;
    }

}
